;(function() {
	$("#example-tabs").steps({
	    headerTag: "h3",
	    bodyTag: "section",
	    transitionEffect: "slideLeft",
	    enableFinishButton: false,
	    enablePagination: false,
	    enableAllSteps: true,
	    titleTemplate: "#title#",
	    cssClass: "tabcontrol"
	});
	$( ".alarm" ).timeDropper({format:"HH:mm"});
	init_parsley("#validate-form-1");
	init_parsley("#validate-form-2");
	init_parsley("#validate-form-3");
	init_parsley("#validate-form-4");
	function init_parsley(node){
		$(node).parsley({
	        successClass: 'has-success',
	        errorClass: 'has-error',
	        errors: {
	            classHandler: function(el) {
	                return $(el).closest('.form-group');
	            },
	            errorsWrapper: '<ul class=\"help-block list-unstyled\"></ul>',
	            errorElem: '<li></li>'
	        }
		});
	}
	
	$(".card-form-submit").click(function(){
			var step=$(this).attr("data-step");
			if(step==4){
				var time_1=$("#time_1").val();
		        var time_2=$("#time_2").val();
		        var time_3=$("#time_3").val();
		        var time_4=$("#time_4").val();
		       	if(time_1>time_2){
		       		toastr['error']("错峰段请按照从小到大的顺序排列");
		       		return;
		       	}
		       	if(time_2>time_3){
		       		toastr['error']("错峰段请按照从小到大的顺序排列");
		       		return;
		       	}
		       	if(time_3>time_4){
		       		toastr['error']("错峰段请按照从小到大的顺序排列");
		       		return;
		       	}
		       	if(time_1>time_4){
		       		toastr['error']("错峰段请按照从小到大的顺序排列");
		       		return;
		       	}
		       	$("#time_sets").val(time_1+"-"+time_2+","+time_3+"-"+time_4);
			}
	   		var flag=$('#validate-form-'+step).parsley('validate' );
	   		if(flag){
	   			loading();
	   			$.post(
	   				"/gym/GymCard/add",
	   				$('#validate-form-'+step).serialize(),
	   				function(data){
	   					close_loading();
			      		if(data.flag){
			      			$("#myModal").modal("hide");
			      			toastr['success']("操作成功！", ''); 
			      			$("#myform #btn-advanced-refresh").trigger("click");// 刷新页面
			      		}else{
			      		 	toastr['error'](data.msg,"操作失败！"); 
			      		}
	   				}
	   			);
	   		}
	})
})();
